package com.dhnsoft.shortLink.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dhnsoft.shortLink.admin.common.convention.result.Result;
import com.dhnsoft.shortLink.admin.remote.ShortLinkRemoteService;
import com.dhnsoft.shortLink.admin.remote.dto.req.ShortLinkCreateReqDTO;
import com.dhnsoft.shortLink.admin.remote.dto.req.ShortLinkPageReqDTO;
import com.dhnsoft.shortLink.admin.remote.dto.resp.ShortLinkCreateRespDTO;
import com.dhnsoft.shortLink.admin.remote.dto.resp.ShortLinkPageRespDTO;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: ShortLinkController
 * Package: com.dhnsoft.shortLink.admin.controller
 * Description:
 *
 * @Author dhn
 * @Create 2024/3/24 15:31
 * @Version 1.0
 */

@RestController
public class ShortLinkController {
    static ShortLinkRemoteService shortLinkRemoteService = new ShortLinkRemoteService() {
    };

    /**
     * 创建短链接
     * */
    @PostMapping("/api/short-link/admin/v1/create")
    public Result<ShortLinkCreateRespDTO> createShortLink(@RequestBody ShortLinkCreateReqDTO requestParam){
        return shortLinkRemoteService.createShortLink(requestParam);
    }


    /**
     * 短链接分页
     * */
    @GetMapping("/api/short-link/admin/v1/page")
    public Result<IPage<ShortLinkPageRespDTO>> pageShortLink(ShortLinkPageReqDTO requestParam){
        return shortLinkRemoteService.pageShortLink(requestParam);
    }

    /**
     * 获取原始链接标题
     * */

    @GetMapping("/api/short-link/admin/v1/title")
    public Result<String> getTitleByUrl(@RequestParam("url") String url){
        return shortLinkRemoteService.getTitleByUrl(url);
    }
}

